package com.sxkiler.demo.maintest.management;

import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
import java.util.List;

public class JMemInfoService {

    final static int loopCount = 10000000;

    public static void main(String args[]){
        Runnable runnable = new Runnable() {
            @Override
            public void run() {


                List list = new ArrayList();
                for(int i=0;i<100;i++){
                    for(int j = 0 ;j<loopCount;j++){
                        list.add("2020-04-01~2020-05-30");
                    }
                    printThreadInfo();
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        new Thread(runnable).start();
        new Thread(runnable).start();
        new Thread(runnable).start();
        new Thread(runnable).start();
        new Thread(runnable).start();
        new Thread(runnable).start();
        new Thread(runnable).start();
        new Thread(runnable).start();
        new Thread(runnable).start();
        new Thread(runnable).start();
    }

    public static void printThreadInfo(){
        ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
        MemoryMXBean memMXBean = ManagementFactory.getMemoryMXBean();
        System.out.println("getCurrentThreadCpuTime="+threadBean.getCurrentThreadCpuTime());
        System.out.println("getHeapMemoryUsage="+memMXBean.getHeapMemoryUsage());
        System.out.println("getNonHeapMemoryUsage="+memMXBean.getNonHeapMemoryUsage());
    }
}
